import 'package:flutter/material.dart';
import 'package:network_plugin/network_plugin.dart';

import '../model/hotkey_info.dart';

class TestPage extends StatefulWidget {
  @override
  _TestPageState createState() => _TestPageState();
}

class _TestPageState extends State<TestPage> {
  List<HotkeyInfo> list;
  String data;

  @override
  void initState() {
    super.initState();

    /// test https://www.wanandroid.com//hotkey/json
    NetworkPlugin.get("hotkey/json").then((response) {
      if (response?.hasData() == true) {
        list = (response.data as List)
            .map((mapJson) => HotkeyInfo.fromJson(mapJson))
            .toList();
        setState(() {});
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
        itemCount: list?.length ?? 0,
        itemBuilder: (BuildContext context, int index) {
          return Container(
            alignment: Alignment.center,
            child: Text(list[index].name),
          );
        });
  }
}
